﻿#include <iostream>
#include <string>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>

std::map<std::string, std::string> numeros = {
    {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"},
    {"four", "4"}, {"five", "5"}, {"six", "6"}, {"seven", "7"},
    {"eight", "8"}, {"nine", "9"}
};

bool is_prime(int num) {
    if (num <= 1) return false;
    for (int i = 2; i < num; ++i) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    std::vector<std::string> num_words;
    std::string word;
    while (iss >> word) {
        num_words.push_back(word);
    }

    std::string num_str;
    try {
        for (const auto& w : num_words) {
            num_str += numeros.at(w);
        }
    }
    catch (const std::out_of_range&) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int num = std::stoi(num_str);

    int less_prime = num;
    int bigger_prime = num;

    while (!is_prime(less_prime)) {
        less_prime--;
    }

    while (!is_prime(bigger_prime)) {
        bigger_prime++;
    }

    if (num - less_prime < bigger_prime - num) {
        std::cout << less_prime << std::endl;
    }
    else {
        std::cout << bigger_prime << std::endl;
    }

    return 0;
}


